package Vista;
import javax.swing.*;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;

public class AyudaParaJugar {

	JFrame unFrame;
	JLabel unPanel;
	ImageIcon imagen;
	
	public AyudaParaJugar(int pagina){
		armarPanel(pagina);
		inicializarFrame();
	}
	
	public void armarPanel(int pagina){
		unPanel = new JLabel();
		
		imagen = new ImageIcon("imagenes/paraAyuda0"+pagina+".jpg");
		unPanel = new JLabel(imagen);
		
		unPanel.addMouseListener(new AccionDelClick(pagina));
		unPanel.addMouseMotionListener(new AccionMovimientoMouse(pagina));
	}
	
	public void inicializarFrame(){
		unFrame = new JFrame();
		
		unFrame.setBackground(Color.black);
		unFrame.setSize(imagen.getIconWidth()+2,imagen.getIconHeight()+33);
		unFrame.setContentPane(unPanel);
		unFrame.addWindowListener(new MonitorVentanaBasica());
		
		unFrame.setResizable(false);
		unFrame.setTitle("Pooglins---Ayuda");
		unFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		Dimension pantallaResolucion = Toolkit.getDefaultToolkit().getScreenSize();
		
		int x =(int)Math.round(pantallaResolucion.getWidth()/2)-(int)Math.round(unFrame.getSize().getWidth()/2);
		int y =(int)Math.round(pantallaResolucion.getHeight()/2)-(int)Math.round(unFrame.getSize().getHeight()/2);
		unFrame.setLocation(x,y);
		unFrame.setVisible(true);
	}
	
	private class AccionMovimientoMouse extends MouseMotionAdapter{
		private Rectangle botonAtras;
		private Rectangle botonJugar;
		private Rectangle botonSiguiente;
		private int pagina;
		
		public AccionMovimientoMouse(int pagina){
			botonAtras = new Rectangle(30,375,80,25);
			botonJugar = new Rectangle(300,375,70,25);
			botonSiguiente = new Rectangle(540,375,100,25);
			this.pagina = pagina;
		}
		
		public void mouseMoved(MouseEvent e){
			int xMouse = e.getX();
			int yMouse = e.getY();
			
			if (((botonJugar.contains(xMouse, yMouse)))
				|| ((pagina > 1) && ((botonAtras.contains(xMouse, yMouse))))
				|| ((pagina < 4) && ((botonSiguiente.contains(xMouse, yMouse))))){
					unPanel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			}else{
				unPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
			}
		}
	}
	
	private class AccionDelClick extends MouseAdapter{
		private Rectangle botonAtras;
		private Rectangle botonJugar;
		private Rectangle botonSiguiente;
		private int pagina;
		
		public AccionDelClick(int pagina){
			botonAtras = new Rectangle(30,375,80,25);
			botonJugar = new Rectangle(300,375,70,25);
			botonSiguiente = new Rectangle(540,375,100,25);
			this.pagina = pagina;
		}
		
		public void mouseClicked(MouseEvent e) {
			int xMouse = e.getX();
			int yMouse = e.getY();
			
			if ((botonJugar.contains(xMouse, yMouse))){
				new MenuInicial();
				unFrame.setVisible(false);
			}
			if (((botonAtras.contains(xMouse, yMouse))) && (pagina > 1)){
				pagina--;
				new AyudaParaJugar(pagina);
				unFrame.setVisible(false);
			}
			if (((botonSiguiente.contains(xMouse, yMouse))) && (pagina < 4)){
				pagina++;
				new AyudaParaJugar(pagina);
				unFrame.setVisible(false);
			}
		}
	}
	
}
